﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HYBYSoft.Company.Models;

namespace HYBYSoft.Company.WebSite.Controllers
{
    public class HomeController : Controller
    {

        /// <summary>
        /// 数据库上下文
        /// </summary>
        CompanySiteEntities _db = new CompanySiteEntities();

        /// <summary>
        /// 公司站点首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var company = _db.Companies.FirstOrDefault();

            //获得已发布的公司最新动态
            var news = (from p in _db.Articles
                           join c in _db.Categories on p.CategoryID equals c.CategoryID
                           where p.CategoryID == 1 && p.IsRelease == 1
                            orderby p.CreateTime descending
                           select p).Take(10);

            ViewBag.News = news;

            return View(company);
        }
    }
}
